#include "page_mode2.h"
#include "R.h"
#include "wind_mgr.h"

PageMode2::PageMode2(ViewGroup *mWindPageBox, int mode)
    : PageBase(mWindPageBox, "@layout/can_shu_setting", PAGE_MODE2){
    // View *canShuSettingView = LayoutInflater::from(getContext())->inflate("@layout/can_shu_setting", this);
    // new PageBase(this, "@layout/can_shu_setting",PAGE_MODE2);
    // this->removeView(canShuSettingView);
    // // delete canShuSettingView;

    // View *canShuSettingView = LayoutInflater::from(getContext())->inflate("@layout/page_home", this);

    /**
     * 
     * catalog1Picker
     * 
     * 鲜蒸
     * 嫩烤
     * 香炸
     * 炖焗
     */
    std::vector<std::string> catalogList;
    catalogList.push_back("鲜蒸");
    catalogList.push_back("嫩烤");
    catalogList.push_back("香炸");
    catalogList.push_back("炖焗");

    /**
     * 
     * numberPickerUp
     * 
     * 3D 热风
     * 上下烤
     * 独立烘培
     */
    std::vector<std::string> numberPickerUpList;
    numberPickerUpList.push_back("3D热风");
    numberPickerUpList.push_back("上下烤");
    numberPickerUpList.push_back("独立烘培");

    /**
     * 
     * numberPickerWeiBo
     * 
     * 低
     * 中
     * 高
     */
    std::vector<std::string> numberPickerWeiBoList;
    numberPickerWeiBoList.push_back("低");
    numberPickerWeiBoList.push_back("中");
    numberPickerWeiBoList.push_back("高");

    /**
     * 
     * numberPickerZhengQi
     * 
     * 低湿
     * 中湿
     * 高湿
     */
    std::vector<std::string> numberPickerZhengQiList;
    numberPickerZhengQiList.push_back("低湿");
    numberPickerZhengQiList.push_back("中湿");
    numberPickerZhengQiList.push_back("高湿");

    ViewGroup* catalog1 = (ViewGroup *)dPageLayout->findViewById(demo::R::id::relativeLayout1);
    
    NumberPicker* catalog1Picker = (NumberPicker *)dPageLayout->findViewById(demo::R::id::catalog1);
    // LOGE("dPageLayout_mode2:%p", dPageLayout);
    // LOGE("catalog1Picker_mode2:%p", catalog1Picker);
    NumberPicker* numberPickerUp = (NumberPicker *)dPageLayout->findViewById(demo::R::id::number_picker_up);
    NumberPicker* numberPickerTemperature = (NumberPicker *)dPageLayout->findViewById(demo::R::id::temperature);
    NumberPicker* numberPickerHour = (NumberPicker *)dPageLayout->findViewById(demo::R::id::hour);
    NumberPicker* numberPickerMinute = (NumberPicker *)dPageLayout->findViewById(demo::R::id::minute);
    NumberPicker* numberPickerWeiBo = (NumberPicker *)dPageLayout->findViewById(demo::R::id::np_wei_bo_fu_zhu);
    NumberPicker* numberPickerZhengQi = (NumberPicker *)dPageLayout->findViewById(demo::R::id::np_zheng_qi_fu_zhu);
    
    catalog1Picker->setFormatter([this, catalogList](int value){
        if (value < catalogList.size()){
            return catalogList.at(value);
        } else {
            return std::string("未知");
        }
    });
    catalog1Picker->setValue(mode);

    numberPickerUp->setFormatter([this, numberPickerUpList](int value){
        if (value < numberPickerUpList.size()) {
            return numberPickerUpList.at(value);
        } else {
            return std::string("未知");
        }
    });
    numberPickerUp->setValue(1);
    numberPickerTemperature->setScrollBarStyle(View::SCROLLBARS_INSIDE_OVERLAY);

    numberPickerTemperature->setFormatter([this](int value){
        return std::to_string(value);
    });
    numberPickerTemperature->setValue(120);

    numberPickerHour->setFormatter([this](int value){
        if (23 - value < 10) {
            return std::to_string(23 - value).insert(0, 1, '0');
        } else {
            return std::to_string(23 - value);
        }
    });
    numberPickerHour->setValue(22);

    numberPickerMinute->setFormatter([this](int value){
        return std::to_string(59 - value);
    });
    numberPickerMinute->setValue(58);

    numberPickerWeiBo->setFormatter([this, numberPickerWeiBoList](int value){
        return std::string(numberPickerWeiBoList.at(value));
    });
    numberPickerWeiBo->setValue(1);

    numberPickerZhengQi->setFormatter([this, numberPickerZhengQiList](int value){
        return std::string(numberPickerZhengQiList.at(value));
    });
    numberPickerZhengQi->setValue(2);

    // catalog1->setOnClickListener([this](View &v ){
    //     // this->close();
    //     new HomeWindow2();
    // });

    ViewGroup *goToHomeLayout = (ViewGroup *)dPageLayout->findViewById(demo::R::id::go_to_home);
    goToHomeLayout->setOnClickListener([this](View &){
        d_windMgr->showPage(PAGE_MODE1);
    });
    

    ViewGroup *linearGroup = (ViewGroup *)dPageLayout->findViewById(demo::R::id::mode_2_group);
    ((BitmapDrawable *)((LayerDrawable *)linearGroup->getBackground())->getDrawable(10))->setFilterBitmap(true);
    ((BitmapDrawable *)((LayerDrawable *)linearGroup->getBackground())->getDrawable(9))->setFilterBitmap(true);
}

PageMode2::~PageMode2() {
}
